package estatistico.util;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.jar.Attributes;
import java.util.jar.Manifest;

class PackageUtils {

    public static List<String> getMainClass(File jarName) throws MalformedURLException, IOException {
        ArrayList<String> classes = new ArrayList();

        URL url = new URL("jar:file:/" + jarName.getAbsolutePath().replace("\\", "/") + "!/META-INF/MANIFEST.MF");
        InputStream is = url.openStream();
        if (is != null) {
            Manifest manifest = new Manifest(is);
            Attributes mainAttribs = manifest.getMainAttributes();
            classes.add(mainAttribs.getValue(Attributes.Name.MAIN_CLASS));
            classes.add(mainAttribs.getValue("Bundle-Name"));
        }
        return classes;
    }
}